package com.jsgt.greekfire.ui.wallet.add

import android.app.Activity
import android.content.Intent
import androidx.activity.result.ActivityResultCallback
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import com.fhx.core.base.BaseActivity
import com.fhx.core.goToActivity
import com.fhx.core.utils.ToastUtils
import com.jsgt.greekfire.R
import com.jsgt.greekfire.ui.dialog.ManageAddWalletDialog
import kotlinx.android.synthetic.main.activity_add_wallet.*

class AddWalletActivity : BaseActivity() {

    private val addWalletDialog: ManageAddWalletDialog by lazy {
        ManageAddWalletDialog("ATR").createListener {
            val intent = Intent(this, CreateWalletActivity::class.java)
            intent.putExtra("coin", "ATR")
            launcher?.launch(intent)

//            ToastUtils.show(R.string.not_yet_open)
        }.mnemonicListener {
            val intent = Intent(this, ImportWalletMnemonicActivity::class.java)
            intent.putExtra("coin", "ATR")
            launcher?.launch(intent)
        }.keyListener {
            val intent = Intent(this, ImportWalletKeyActivity::class.java)
            intent.putExtra("coin", "ATR")
            launcher?.launch(intent)
        }
    }

    private var launcher: ActivityResultLauncher<Intent>? = null

    override fun needFitsSystemWindows(): Boolean {
        return false
    }

    override fun getLayoutId(): Int {
        return R.layout.activity_add_wallet
    }

    override fun main() {
        setStatusBar(R.color.transparent, false, R.color.white)
        title = getString(R.string.add_wallet)
        vCoin.setOnClickListener {
            addWalletDialog.show(supportFragmentManager, "addWallet")
        }
        launcher = registerForActivityResult(
            ActivityResultContracts.StartActivityForResult()
        ) {
            if (it.resultCode == Activity.RESULT_OK) {
                setResult(Activity.RESULT_OK)
                finish()
            }
        }
    }
}